<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<base href="<%=basePath%>">
<!-- <base href="http://192.168.0.100:8080/YMGW/"> -->
<title>总部</title>
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/css/bootstrap.min.css">
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/css/main.css">

<script src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
<script src="${pageContext.request.contextPath}/js/bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/js/main.js"></script>

<script>
/* $(function() {
	$("#supermarketId").val(localStorage.getItem("id"));
	$.post(
		"productaAction/getSupermarketSet",
		{
			superID : localStorage.getItem("id")
		},
		function(data) {
			$("input[name='upSendMoney']").val(data.upSendMoney);
			$("input[name='freeSendMoney']").val(data.freeSendMoney);
			$("input[name='sendMoney']").val(data.sendMoney);
			$("input[name='sendPeople']").val(data.sendPeople);
			$("input[name='sendTime']").val(data.sendTime);
			$("input[name='superName']").val(localStorage.getItem("name"));
			$("textarea[name='afterService']").val(data.afterService);
			$("input[name='sendPhone']").val(data.sendPhone);
		}, "json");
}) */
</script>
</head>
<body>
	<%@ include file="header.jsp"%>
	<%@ include file="left.jsp"%>
	<div id="index"
		style="position: absolute;left: 180px;top: 80px;bottom: 0;right: 0;">
		<section id="main">
			<div class="scrollbar1-1" id="style1-1">
				<div class="main_div">
					<div class="main_title">
						<span>分成设置</span>
					</div>
					<form class="form-horizontal" style="margin-top: 30px"
						id="uploadForm">
						<div class="form-group">
							<label class="col-xs-2 control-label">总部广告分成：</label>
							<div class="col-xs-1">

								<input type="number"
									oninput="if(value.length>4)value=value.slice(0,4)"
									class="form-control" id="headAdDivided">
							</div>
							<label class="col-xs-1 control-label" style="text-align:left">%</label>
						</div>
						<div class="form-group">
							<label class="col-xs-2 control-label">代理广告分成：</label>
							<div class="col-xs-1">
								<input type="number"
									oninput="if(value.length>4)value=value.slice(0,4)"
									class="form-control" id="agentAdDivided">
							</div>
							<label class="col-xs-1 control-label" style="text-align:left">%</label>
						</div>
						<div class="form-group" style="margin-top:40px;color:green">
							<label class="col-xs-2 control-label">总部直营分成：</label>
							<div class="col-xs-1">
								<input type="number"
									oninput="if(value.length>4)value=value.slice(0,4)"
									class="form-control" id="headDirectDivided">
							</div>
							<label class="col-xs-1 control-label" style="text-align:left">%</label>
						</div>
						<div class="form-group" style="color:green">
							<label class="col-xs-2 control-label">代理商直营分成：</label>
							<div class="col-xs-1">
								<input type="number"
									oninput="if(value.length>4)value=value.slice(0,4)"
									class="form-control" id="agentDirectDivided">
							</div>
							<label class="col-xs-1 control-label" style="text-align:left">%</label>
						</div>
						<div class="form-group" style="color:green">
							<label class="col-xs-2 control-label">超市直营分成：</label>
							<div class="col-xs-1">
								<input type="number"
									oninput="if(value.length>4)value=value.slice(0,4)"
									class="form-control" id="superDirectDivided">
							</div>
							<label class="col-xs-1 control-label" style="text-align:left">%</label>
						</div>
						<div class="form-group" style="margin-top:40px;color:red">
							<label class="col-xs-2 control-label">总部团购分成：</label>
							<div class="col-xs-1">
								<input type="number"
									oninput="if(value.length>4)value=value.slice(0,4)"
									class="form-control" id="headGroupDivided">
							</div>
							<label class="col-xs-1 control-label" style="text-align:left">%</label>
						</div>
						<div class="form-group" style="color:red">
							<label class="col-xs-2 control-label">代理商团购分成：</label>
							<div class="col-xs-1">
								<input type="number"
									oninput="if(value.length>4)value=value.slice(0,4)"
									class="form-control" id="agentGroupDivided">
							</div>
							<label class="col-xs-1 control-label" style="text-align:left">%</label>
						</div>
						<div class="form-group" style="color:red">
							<label class="col-xs-2 control-label">超市团购分成：</label>
							<div class="col-xs-1">
								<input type="number"
									oninput="if(value.length>4)value=value.slice(0,4)"
									class="form-control" id="superGroupDivided">
							</div>
							<label class="col-xs-1 control-label" style="text-align:left">%</label>
						</div>
						<div class="form-group">
							<div class="col-xs-2 col-xs-offset-2">
								<button onclick="sureChange()" type="button"
									class="col-xs-4 btn btn-primary">申请修改</button>
							</div>
						</div>
					</form>
				</div>
			</div>
		</section>
	</div>
	<script>
		$(function() {
			selectinfo()
		})
	
		function sureChange() {
			var allInput = $("#uploadForm").find("input");
			var config = true;
			var config2 = false;
			var headAdDivided = $("#headAdDivided").val();
			var agentAdDivided = $("#agentAdDivided").val();
			var headDirectDivided = $("#headDirectDivided").val();
			var agentDirectDivided = $("#agentDirectDivided").val();
			var superDirectDivided = $("#superDirectDivided").val();
			var headGroupDivided = $("#headGroupDivided").val();
			var agentGroupDivided = $("#agentGroupDivided").val();
			var superGroupDivided = $("#superGroupDivided").val();
			var reg = /^\d{1,2}\.?\d{1}$/;
			for (var ids = 0; ids < allInput.length; ids++) {
				if (reg.test(allInput[ids].value)) {
				} else {
					config = false;
				}
			}
			if ((parseFloat(headAdDivided) + parseFloat(agentAdDivided)).toFixed(1) == 100.0) {
				if ((parseFloat(headDirectDivided) + parseFloat(agentDirectDivided) + parseFloat(superDirectDivided)).toFixed(1) == 100.0) {
					if ((parseFloat(headGroupDivided) + parseFloat(agentGroupDivided) + parseFloat(superGroupDivided)).toFixed(1) == 100.0) {
						config2 = true;
					}
				}
			}
			if (config && config2) {
				$.post(urls + "headAction/updateDividedInto",
					{
						id : 1,
						headAdDivided : headAdDivided,
						agentAdDivided : agentAdDivided,
						headZyDivided : headDirectDivided,
						agentZyDivided : agentDirectDivided,
						superZyDivided : superDirectDivided,
						headTgDivided : headGroupDivided,
						agentTgDivided : agentGroupDivided,
						superTgDivided : superGroupDivided,
					},
					function(res) {
						if (res == true) {
							alert("修改成功")
						} else {
							alert("修改失败")
						}
					}
				)
			} else {
				alert("错误数据，请检查后提交")
			}
	
		}
		function selectinfo() {
			$.post(urls + "headAction/selectDividedInto", function(res) {
				if (res) {
					$("#headAdDivided").val(res.headAdDivided);
					$("#agentAdDivided").val(res.agentAdDivided);
					$("#headDirectDivided").val(res.headZyDivided);
					$("#agentDirectDivided").val(res.agentZyDivided);
					$("#superDirectDivided").val(res.superZyDivided);
					$("#headGroupDivided").val(res.headTgDivided);
					$("#agentGroupDivided").val(res.agentTgDivided);
					$("#superGroupDivided").val(res.superTgDivided);
				}
	
			})
		}
	</script>
</body>
</html>
